

global path"D:\SXMhomework" 






* table1 partA
use "$path/datasets/main_dataset.dta", clear

eret clear
estpost sum gewinn_norm listenplatz_norm age non_university_phd university phd architect businessmanwoman  engineer lawyer  civil_administration  teacher  employed selfemployed student retired housewifehusband
esttab using "$path/202221050104孙晓萌/Table1_PartA.rtf", replace style(tab) ///
mlabel(,none) ///
cells("count(fmt(%6.0f)) mean(fmt(%6.3f)) sd(fmt(%6.3f)) min(fmt(%6.3f)) max(fmt(%6.3f)) ") ///
collabels(none) ///

varlabels( gewinn_norm "Rank change (normalized)" listenplatz_norm "Initial list rank (normalized)" age "Age" non_university_phd "High school" university "University" phd "Phd" architect "Architect" businessmanwoman "Businesswoman/-man"  engineer "Engineer" lawyer "Lawyer"  civil_administration "Civil administration"  teacher "Teacher"  employed "Employed" selfemployed "Self-employed" student "Student" retired "Retired" housewifehusband "Housewife/-husband"  )



* table1 partB
use "$path/datasets/main_dataset.dta", clear

eret clear
keep if female==1
estpost sum gewinn_norm listenplatz_norm age non_university_phd university phd architect businessmanwoman  engineer lawyer  civil_administration  teacher  employed selfemployed student retired housewifehusband


esttab using "$path/202221050104孙晓萌/Table1_PartB.rtf", replace style(tab) ///
mlabel(,none) ///
cells("count(fmt(%6.0f)) mean(fmt(%6.3f)) sd(fmt(%6.3f)) min(fmt(%6.3f)) max(fmt(%6.3f)) ") ///
collabels(none) ///
varlabels( gewinn_norm "Rank change (normalized)" listenplatz_norm "Initial list rank (normalized)" age "Age" non_university_phd "High school" university "University" phd "Phd" architect "Architect" businessmanwoman "Businesswoman/-man"  engineer "Engineer" lawyer "Lawyer"  civil_administration "Civil administration"  teacher "Teacher"  employed "Employed" selfemployed "Self-employed" student "Student" retired "Retired" housewifehusband "Housewife/-husband"  ) ///





* table2

use "$path/datasets/main_dataset.dta", clear
adopath + $path/ado_files/

* setup datasets: keep only mixed-gender mayor elections and women candidates
keep if rdd_sample==1
keep if female==1

* first determine optimal CCT BW
bandwidth_and_weights, depvar(gewinn_norm) var(margin_1)  bwmethod(mserd) kernel(tri) degree(1)

ivreg2 gewinn_norm female_mayor margin_1 inter_1   if abs(margin_1)<$bw_opt  [pw=weight], r cluster(gkz ) partial(margin_1 inter_1 )
est store m1
estadd local bw "mserd"
estadd local degree "Linear"
estadd local bw_length  $bw_opt
unique gkz_jahr if e(sample)
estadd local num_of_elections  `"`r(sum)'"'
sum gewinn_norm if e(sample)
estadd scalar  mean_depvar =r(mean)
estadd scalar sd_depvar =r(sd)

ivreg2 gewinn_norm female_mayor margin_1 inter_1   if abs(margin_1)<$bw_half  [pw=weight_half], r cluster(gkz ) partial(margin_1 inter_1 )
est store m2
estadd local bw "mserd/2"
estadd local degree "Linear"
estadd local bw_length  $bw_half
unique gkz_jahr if e(sample)
estadd local num_of_elections  `"`r(sum)'"'
sum gewinn_norm if e(sample)
estadd scalar  mean_depvar =r(mean)
estadd scalar sd_depvar =r(sd)


ivreg2 gewinn_norm female_mayor margin_1 inter_1   if abs(margin_1)<$bw_double  [pw=weight_double], r cluster(gkz ) partial(margin_1 inter_1 )
est store m3
estadd local bw "2mserd"
estadd local degree "Linear"
estadd local bw_length  $bw_double
unique gkz_jahr if e(sample)
estadd local num_of_elections  `"`r(sum)'"'
sum gewinn_norm if e(sample)
estadd scalar  mean_depvar =r(mean)
estadd scalar sd_depvar =r(sd)


* degree 1 with IK
* first determine optimal IK BW
bandwidth_and_weights, depvar(gewinn_norm) var(margin_1)  bwmethod(cerrd) kernel(tri) degree(1)

ivreg2 gewinn_norm female_mayor margin_1 inter_1   if abs(margin_1)<$bw_opt  [pw=weight] , r cluster(gkz ) partial(margin_1 inter_1 )
est store m4
estadd local bw "cerrd"
estadd local degree "Quadratic"
estadd local bw_length $bw_opt
unique gkz_jahr if e(sample)
estadd local num_of_elections  `"`r(sum)'"'
sum gewinn_norm if e(sample)
estadd scalar  mean_depvar =r(mean)
estadd scalar sd_depvar =r(sd)


* degree 2 with ccerd
*  first determine  optimal BW for deg = 2
bandwidth_and_weights, depvar(gewinn_norm) var(margin_1)  bwmethod(mserd) kernel(tri) degree(2)

ivreg2 gewinn_norm female_mayor margin_1 inter_1 margin_2 inter_2   if abs(margin_1)<$bw_opt  [pw=weight] , r cluster(gkz ) partial(margin_1 inter_1 margin_2 inter_2)
est store m5
estadd local bw "mserd/2"
estadd local degree "Linear"
estadd local bw_length $bw_opt
unique gkz_jahr if e(sample)
estadd local num_of_elections  `"`r(sum)'"'
sum gewinn_norm if e(sample)
estadd scalar  mean_depvar =r(mean)
estadd scalar sd_depvar =r(sd)

********************************************************************************************************************************************
* table 

esttab m1 m2 m3 m4 m5 using "$path/202221050104孙晓萌/Table2.rtf", replace style(tab) order( ) mlabel(,none) ///
cells(b(label(coef.) star fmt(%8.3f) ) se(label((z)) par fmt(%6.3f))) ///
collabels(none) ///
keep (female_mayor) ///
  stats(bw bw_length degree N num_of_elections  N_clust mean_depvar sd_depvar, layout( @ @ @ @ @ @ @ (@) )  fmt( %~#s %9.2f %~# %9.0g %9.0g %9.0f %9.2f %9.2f  ) ///
 labels("Bandwidth type" "Bandwidth size" "Polynomial"   "N" "Elections" "Municipalities" "Mean" "SD"  )) ///
starlevels(* 0.10 ** 0.05 *** 0.01)  





* table A4 panelA
use "$path/datasets/mayor_election_data.dta", clear

* now merge with muni characteristics datase

sort gkz jahr
merge 1:1 gkz jahr using $path/datasets/municipality_characteristics_data.dta
drop _merge

eret clear
estpost sum  log_bevoelkerung log_flaeche  log_debt_pc log_tottaxrev_pc log_gemeinde_beschaef_pc  log_female_sh_gem_besch   log_tot_beschaeft_pc log_female_share_totbesch   log_prod_share_tot       log_female_share_prod    if male_mayor==0
matrix meanf1=e(mean)
matrix list meanf1
estpost sum log_bevoelkerung log_flaeche  log_debt_pc log_tottaxrev_pc log_gemeinde_beschaef_pc  log_female_sh_gem_besch   log_tot_beschaeft_pc log_female_share_totbesch   log_prod_share_tot       log_female_share_prod     if male_mayor==1
matrix meanf2=e(mean)
matrix list meanf2

estpost ttest log_bevoelkerung log_flaeche  log_debt_pc log_tottaxrev_pc log_gemeinde_beschaef_pc  log_female_sh_gem_besch   log_tot_beschaeft_pc log_female_share_totbesch   log_prod_share_tot       log_female_share_prod   , by(male_mayor)
estadd matrix meanf1
estadd matrix meanf2


esttab  using "$path/202221050104孙晓萌/TableA4_PanelA.rtf", replace order(log_bevoelkerung log_flaeche  log_debt_pc log_tottaxrev_pc log_tot_beschaeft_pc log_female_share_totbesch log_gemeinde_beschaef_pc  log_female_sh_gem_besch      log_prod_share_tot       log_female_share_prod    ) cells("meanf1(fmt(3))  meanf2(fmt(3))   b(star fmt(3)) se(fmt(3)) count(fmt(0))") star(* 0.1 ** .05 *** 0.01) ///
collabels(  "Female mayor" "Male mayor"  "Diff." "Std. Error" "Obs.") ///
varlabels(log_bevoelkerung "Log(population)" log_flaeche "Log(land area)"  log_debt_pc "Log(debt p.c.)" log_tottaxrev_pc "Log(tax revenues p.c.)" log_tot_beschaeft_pc "Log(total employment p.c.)" log_female_share_totbesch "Log(female share, local gov. employment)"  log_gemeinde_beschaef_pc  "Log(public employment p.c.)" log_female_sh_gem_besch "Log(female share, local gov. employment)"       log_prod_share_tot "Log(manufacturing / total employment)"      log_female_share_prod "Log(share female, manufacturing)")



* table A4 panelB
use "$path/datasets/mayor_election_data.dta", clear

* now merge with muni characteristics datase

sort gkz jahr
merge 1:1 gkz jahr using $path/datasets/municipality_characteristics_data.dta
drop _merge
keep if abs(margin_1)<10
eret clear
estpost sum  log_bevoelkerung log_flaeche  log_debt_pc log_tottaxrev_pc log_gemeinde_beschaef_pc  log_female_sh_gem_besch   log_tot_beschaeft_pc log_female_share_totbesch   log_prod_share_tot       log_female_share_prod    if male_mayor==0
matrix meanf1=e(mean)
matrix list meanf1
estpost sum log_bevoelkerung log_flaeche  log_debt_pc log_tottaxrev_pc log_gemeinde_beschaef_pc  log_female_sh_gem_besch   log_tot_beschaeft_pc log_female_share_totbesch   log_prod_share_tot       log_female_share_prod     if male_mayor==1
matrix meanf2=e(mean)
matrix list meanf2

estpost ttest log_bevoelkerung log_flaeche  log_debt_pc log_tottaxrev_pc log_gemeinde_beschaef_pc  log_female_sh_gem_besch   log_tot_beschaeft_pc log_female_share_totbesch   log_prod_share_tot       log_female_share_prod   , by(male_mayor)
estadd matrix meanf1
estadd matrix meanf2

esttab  using "$path/202221050104孙晓萌/TableA4_PanelB.rtf", replace order(log_bevoelkerung log_flaeche  log_debt_pc log_tottaxrev_pc log_tot_beschaeft_pc log_female_share_totbesch log_gemeinde_beschaef_pc  log_female_sh_gem_besch      log_prod_share_tot       log_female_share_prod    ) cells("meanf1(fmt(3))  meanf2(fmt(3))   b(star fmt(3)) se(fmt(3)) count(fmt(0))") star(* 0.1 ** .05 *** 0.01) ///
collabels(  "Female mayor" "Male mayor"  "Diff." "Std. Error" "Obs.") ///
varlabels(log_bevoelkerung "Log(population)" log_flaeche "Log(land area)"  log_debt_pc "Log(debt p.c.)" log_tottaxrev_pc "Log(tax revenues p.c.)" log_tot_beschaeft_pc "Log(total employment p.c.)" log_female_share_totbesch "Log(female share, local gov. employment)"  log_gemeinde_beschaef_pc  "Log(public employment p.c.)" log_female_sh_gem_besch "Log(female share, local gov. employment)"       log_prod_share_tot "Log(manufacturing / total employment)"      log_female_share_prod "Log(share female, manufacturing)")





* table A5

use "$path/datasets/main_dataset.dta", clear

* setup datasets: keep only mixed-gender mayor elections and women candidates
keep if rdd_sample==1
keep if female==1

ivreg2 gewinn_norm  log_bevoelkerung log_flaeche  log_debt_pc log_tottaxrev_pc log_gemeinde_beschaef_pc  log_female_sh_gem_besch   log_tot_beschaeft_pc log_female_share_totbesch   log_prod_share_tot      log_female_share_prod  
predict predicted_rank_change, xb
* keep one observation per election given that each candidate has the same predicted value as municipality characteristics do not vary across candidates
bysort gkz jahr: keep if _n==1


* first determine optimal CCT BW
bandwidth_and_weights, depvar(predicted_rank_change) var(margin_1)  bwmethod(mserd) kernel(tri) degree(1)


ivreg2 predicted_rank_change female_mayor margin_1 inter_1   if abs(margin_1)<$bw_opt  [pw=weight], r cluster(gkz ) partial(margin_1 inter_1 )
estadd local bw "mserd"
estadd local degree "Linear"
estadd local bw_length  $bw_opt
unique gkz_jahr if e(sample)
estadd local num_of_elections  `"`r(sum)'"'
sum predicted_rank_change if e(sample)
estadd scalar  mean_depvar =r(mean)
estadd scalar sd_depvar =r(sd)
est store m1

ivreg2 predicted_rank_change female_mayor margin_1 inter_1   if abs(margin_1)<$bw_half  [pw=weight_half], r cluster(gkz ) partial(margin_1 inter_1 )
estadd local bw "mserd/2"
estadd local degree "Linear"
estadd local bw_length  $bw_half
unique gkz_jahr if e(sample)
estadd local num_of_elections  `"`r(sum)'"'
sum predicted_rank_change if e(sample)
estadd scalar  mean_depvar =r(mean)
estadd scalar sd_depvar =r(sd)
est store m2

ivreg2 predicted_rank_change female_mayor margin_1 inter_1   if abs(margin_1)<$bw_double  [pw=weight_double], r cluster(gkz ) partial(margin_1 inter_1 )
estadd local bw "2mserd"
estadd local degree "Linear"
estadd local bw_length  $bw_double
unique gkz_jahr if e(sample)
estadd local num_of_elections  `"`r(sum)'"'
sum predicted_rank_change if e(sample)
estadd scalar  mean_depvar =r(mean)
estadd scalar sd_depvar =r(sd)
est store m3

* degree 1 with IK
* first determine optimal IK BW
bandwidth_and_weights, depvar(predicted_rank_change) var(margin_1)  bwmethod(cerrd) kernel(tri) degree(1)

ivreg2 predicted_rank_change female_mayor margin_1 inter_1   if abs(margin_1)<$bw_opt  [pw=weight] , r cluster(gkz ) partial(margin_1 inter_1 )
estadd local bw "cerrd"
estadd local degree "Linear"
estadd local bw_length $bw_opt
unique gkz_jahr if e(sample)
estadd local num_of_elections  `"`r(sum)'"'
sum predicted_rank_change if e(sample)
estadd scalar  mean_depvar =r(mean)
estadd scalar sd_depvar =r(sd)
est store m4

* degree 2 with CCT
*  first determine  optimal BW for deg = 2
bandwidth_and_weights, depvar(predicted_rank_change) var(margin_1)  bwmethod(mserd) kernel(tri) degree(2)

ivreg2 predicted_rank_change female_mayor margin_1 inter_1 margin_2 inter_2   if abs(margin_1)<$bw_opt  [pw=weight] , r cluster(gkz ) partial(margin_1 inter_1 margin_2 inter_2)
estadd local bw "mserd"
estadd local degree "Quadratic"
estadd local bw_length $bw_opt
unique gkz_jahr if e(sample)
estadd local num_of_elections  `"`r(sum)'"'
sum predicted_rank_change if e(sample)
estadd scalar  mean_depvar =r(mean)
estadd scalar sd_depvar =r(sd)
est store m5
********************************************************************************************************************************************
* table 


esttab  m1 m2 m3 m4 m5 using "$path/202221050104孙晓萌/TableA5.rtf", replace style(tab) order( ) mlabel(,none) ///
cells(b(label(coef.) star fmt(%8.3f) ) se(label((z)) par fmt(%6.3f))) ///
collabels(none) ///
keep (female_mayor) ///
stats(bw bw_length degree N num_of_elections  N_clust mean_depvar sd_depvar , layout( @ @ @ @ @ @ `""@ (@)""' )  fmt( %~#s %9.2f %~# %9.0g %9.0g %9.0f %9.2f %9.2f  ) ///
labels("Bandwidth type" "Bandwidth size" "Polynomial"   "N" "Elections" "Municipalities" "Mean (SD)"  )) ///
  starlevels(* 0.10 ** 0.05 *** 0.01)  
  

* figure2

use "$path/datasets\main_dataset.dta", clear

* setup datasets: keep only mixed-gender mayor elections and women candidates
keep if rdd_sample==1
keep if female==1
bandwidth_and_weights, depvar(gewinn_norm) var(margin_1)  bwmethod(CCT) kernel(tri) degree(1)
rdd_plot  gewinn_norm, includedbw(30)  control(margin_1) binsize(3)  bw($bw_opt) title("Rank improvement of women") xtitle("Female mayoral candidate margin of victory (%)") yscale(-5(2.5)5)  
graph export "$path/202221050104孙晓萌/figure2.pdf", replace
  
